﻿namespace Rage.UI
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Threading;

    public partial class DG_ProgressBar : ChildWindow
    {
        public static void ShowDialog(string percText, string fileText, EventHandler callback)
        {
            DG_ProgressBar window = new DG_ProgressBar() { PercText = percText, };
            if (callback != null) { window.Closed += callback; }
            window.Show();
        }

        public DG_ProgressBar()
        {
            InitializeComponent();

#if !SILVERLIGHT
            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            this.WindowState = System.Windows.WindowState.Normal;
            this.ResizeMode = System.Windows.ResizeMode.NoResize;
#endif
        }

        public MessageBoxResult MessageBoxResult { get; set; }

        public void FinishProgress()
        {
            MessageBoxResult = MessageBoxResult.OK;
            this.Close();
        }

        public void UpdateProgress(double newValue, double ttl, double cntSkipped/*, string curFile*/)
        {
            PB_Progress.Value = ttl > 0 ? newValue / ttl * 100 : 0;
            PercText = string.Format("File {0:#,##0} of {1:#,##0} ({2:0.#%}) ({3:#,###} Skipped / {4:#,###} Remaining)",
                newValue, ttl, PB_Progress.Value / 100d, cntSkipped, ttl - cntSkipped);
        }

        public void AddLineToLog(string src)
        {
            TB_Log.Text += src + "\n";
        }

        public string PercText
        {
            get { return TB_Perc.Text; }
            set { TB_Perc.Text = value; }
        }

        private void BT_Cancel_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult = MessageBoxResult.Cancel;
            this.Close();
        }
    }
}

